from Model import *
from DAL import *
from flask import Flask, render_template, request, jsonify

app = Flask(__name__)
# 车辆信息表操作对象
carInfoDal = CarInfoDAL()
# 车辆库存信息表操作对象
carStockInfoDal = CarStockInfoDAL()
# 车辆使用信息表操作对象
carUseInfoDal = CarUseInfoDAL()
# 工作人员信息表操作对象
workerDal = WorkerDAL()

# 工作人员类型表操作对象
workerTypeDal = WorkerTypeDAL()
# 车辆类型信息表
carTypeDal = CarTypeDAL()
# 车辆状态信息表
carStatusDal = CarStatusDAL()
# 管理员密码
adminPassWordDal = AdminPassWordDAL()



# 主页
@app.route('/')
def index():
    return render_template('index.html')




## 车辆库存
# 车辆库存信息列表
@app.route('/carStockList')
def carStockList():
    result = carStockInfoDal.queryAll()
    return render_template('carStockList.html', info=result)

# 车辆库存信息修改
@app.route('/updateCarStockList/<carType>')
def updateCarStockInfo(carType):
    result = carStockInfoDal.queryByCarType(carType)
    if result is None:
        return "车辆类型信息不存在，请检查重试！ <a href='/carStockList'>返回首页</a>"
    else:
        return render_template('updateCarStockInfo.html', info=result)

# 车辆库存信息修改提交
@app.route('/updateCarStockInfoSubmit', methods=['POST'])
def updateCarStockInfoSubmit():
    carType = request.form.get('carType')
    carAmount = int(request.form.get('carAmount'))
    if carAmount <= 0:
        return f"车辆总量只能输入正整数！ <a href='/updateCarStockList/{carType}'>刷新</a>"
    carTypeHeader = request.form.get('carTypeHeader')
    carTypeHeaderPhone = int(request.form.get('carTypeHeaderPhone'))
    if carTypeHeaderPhone <= 0:
        return f"联系方式有误，请检查重试！ <a href='/updateCarStockList/{carType}'>刷新</a>"
    elif len(str(carTypeHeaderPhone)) != 11:
        return f"联系方式有误，请检查重试！ <a href='/updateCarStockList/{carType}'>刷新</a>"
    carStockInfo = CarStockInfo(carType, carAmount, carTypeHeader, carTypeHeaderPhone)
    result = carStockInfoDal.updateByCarType(carStockInfo)
    if result > 0:
        return "修改成功 <a href='/carStockList'>刷新</a>"
    elif result == 0:
        return "数据未更改 <a href='/carStockList'>刷新</a>"
    elif result == -2:
        return f"输入内容过长，请检查重试！ <a href='/updateCarStockList/{carType}'>刷新</a>"
    
# 车辆库存信息添加
@app.route('/addCarStockInfo')
def addCarStockInfo():
    return render_template('addCarStockInfo.html')

# 车辆库存信息添加提交
@app.route('/addCarStockInfoSubmit', methods=['POST'])
def addCarStockInfoSubmit():
    try:
        carType = request.form.get('carType')
        carAmount = request.form.get('carAmount')
        if int(carAmount) < 0:
            return "车辆数量必须为正数！ <a href='/addCarStockInfo'>刷新</a>"
        carTypeHeader = request.form.get('carTypeHeader')
        carTypeHeaderPhone = request.form.get('carTypeHeaderPhone')
        if int(carTypeHeaderPhone) <= 0:
            return "联系方式有误，请检查重试！ <a href='/addCarStockInfo'>刷新</a>"
        elif len(carTypeHeaderPhone) != 11:
            return "联系方式有误，请检查重试！ <a href='/addCarStockInfo'>刷新</a>"
        carStockInfo = CarStockInfo(carType, carAmount, carTypeHeader, carTypeHeaderPhone)
        result = carTypeDal.insert(carType)
        if result > 0:
            result1 = carStockInfoDal.insert(carStockInfo)
            if result1 > 0:
                return "添加成功 <a href='/carStockList'>刷新</a>"
            else:
                return "添加失败 <a href='/carStockList'>刷新</a>"
        elif result == -1:
            return "车辆类型已存在，请检查重试！ <a href='/addCarStockInfo'>刷新</a>"
        elif result == -2:
            return "输入内容过长，请检查重试！ <a href='/addCarStockInfo'>刷新</a>"
        else:
            return "添加失败 <a href='/carStockList'>刷新</a>"
    except ValueError:
        return "输入不能为空！  <a href='/addCarStockInfo'>刷新</a>"

# 车辆库存信息删除
@app.route('/deleteCarStockList/<carType>')
def deleteCarStockInfo(carType):
    flag = 'deleteCarStockInfo'
    carTypeAll = carTypeDal.queryAll()
    carTypeAllRush=[]
    for i in carTypeAll:
        carTypeAllRush.append(i[0])
    if carType not in carTypeAllRush:
        return f"抱歉，删除失败，车辆类型不存在！ <a href='/carStockList'>返回首页</a>"
    else:
        return render_template('/deleteConfirm.html', delInfo=carType, flag=flag)






## 车辆信息
# 车辆信息列表
@app.route('/carInfoList/<carType>')
def carInfoList(carType):
    result = carInfoDal.queryByCarType(carType)
    return render_template('carInfoList.html', info=result)

# 车辆信息修改
@app.route('/updateCarInfoList/<carNumber>')
def updateCarInfo(carNumber):
    result = carInfoDal.queryByCarNumber(carNumber)
    if result is None:
        return "车辆信息不存在，请检查重试！ <a href='/carStockList'>返回首页</a>"
    else:
        result1 = carStatusDal.queryAll()
        return render_template('updateCarInfo.html', info=result, info1=result1)

# 车辆信息修改提交
@app.route('/updateCarInfoSubmit', methods=['POST'])
def updateCarInfoSubmit():
    carNumber = request.form.get('carNumber')
    carType = request.form.get('carType')
    carStatus = request.form.get('carStatus')
    carYear = request.form.get('carYear')
    if int(carYear) <= 0 or len(carYear) != 4:
        return f"年份只能输入四位正整数！ <a href='/updateCarInfoList/{carNumber}'>刷新</a>"
    carInsuranceDate = request.form.get('carInsuranceDate')
    carCheckDate = request.form.get('carCheckDate')
    carPrice =  float(request.form.get('carPrice'))
    if carPrice <= 0.00:
        return f"车辆价格只能输入正数！ <a href='/updateCarInfoList/{carNumber}'>刷新</a>"
    carHeader = request.form.get('carHeader')
    carHeaderPhone = request.form.get('carHeaderPhone')
    if int(carHeaderPhone) <= 0:
        return f"联系方式有误，请检查重试！ <a href='/updateCarInfoList/{carNumber}'>刷新</a>"
    elif len(carHeaderPhone) != 11:
        return f"联系方式有误，请检查重试！ <a href='/updateCarInfoList/{carNumber}'>刷新</a>"
    carInfo = CarInfo(carNumber, carType, carStatus, carYear, carInsuranceDate, carCheckDate, carPrice, carHeader, carHeaderPhone)
    result = carInfoDal.updateByCarNumber(carInfo)
    if result > 0:
        return f"修改成功 <a href='/carInfoList/{carType}'>刷新</a>"
    elif result == 0:
        return f"数据未更改 <a href='/carInfoList/{carType}'>刷新</a>"
    elif result == -2:
        return f"输入内容过长，请检查重试！ <a href='/updateCarInfoList/{carNumber}'>刷新</a>"

# 车辆信息删除
@app.route('/deleteCarInfoList/<carNumber>')
def deleteCarInfo(carNumber):
    carType = carInfoDal.queryCarTypeByCarNumber(carNumber)
    if carType is None:
        return f"抱歉，删除失败，车辆不存在！ <a href='/carStockList'>返回首页</a>"
    else:
        return render_template('/deleteCarInfoConfirm.html', info=carNumber, info1=carType[0])

# 车辆信息删除提交
@app.route('/deleteCarInfoConfirmSubmit/<carType>', methods=['POST'])
def deleteCarInfoConfirmSubmit(carType):
    carNumber = request.form.get('carNumber')
    passwd = request.form.get('passwd')
    passWord = adminPassWordDal.queryPassWord()
    if passwd == passWord[0]:
        result = carInfoDal.deleteByCarNumber(carNumber)
        if result > 0:
            result1 = carStockInfoDal.carAmountLostOne(carType)
            if result1 > 0:
                return f"删除成功 <a href='/carInfoList/{carType}'>刷新</a>"
            else:
                return f"未知错误 <a href='/carInfoList/{carType}'>刷新</a>"
        else:
            return f"删除失败 <a href='/carInfoList/{carType}'>刷新</a>"
    else:
        return f"抱歉，密码错误，无法确认您的身份！ <a href='/carInfoList/{carType}'>刷新</a>"
 
# 车辆信息添加
@app.route('/addCarInfo')
def addCarInfo():
    result = carTypeDal.queryAll()
    result1 = carStatusDal.queryAll()
    return render_template('addCarInfo.html', info = result, info1 = result1)

# 车辆信息添加提交
@app.route('/addCarInfoSubmit', methods=['POST'])
def addCarInfoSubmit():
    try:
        carNumber = request.form.get('carNumber')
        if len(carNumber) < 7 or len(carNumber) > 8:
            return f"车牌号只有7位和8位（电车）！ <a href='/addCarInfo'>刷新</a>"
        carType = request.form.get('carType')
        carStatus = request.form.get('carStatus')
        carYear = request.form.get('carYear')
        if int(carYear) <= 0 or len(carYear) != 4:
            return f"年份只能输入四位正整数！ <a href='/addCarInfo'>刷新</a>"
        carInsuranceDate = request.form.get('carInsuranceDate')
        carCheckDate = request.form.get('carCheckDate')
        carPrice =  request.form.get('carPrice')
        if float(carPrice) <= 0.00:
            return f"车辆价格只能输入正数！ <a href='/addCarInfo'>刷新</a>"
        carHeader = request.form.get('carHeader')
        carHeaderPhone = request.form.get('carHeaderPhone')
        if int(carHeaderPhone) <= 0:
            return f"联系方式有误，请检查重试！ <a href='/addCarInfo'>刷新</a>"
        elif len(carHeaderPhone) != 11:
            return f"联系方式有误，请检查重试！ <a href='/addCarInfo'>刷新</a>"
        carInfo = CarInfo(carNumber, carType, carStatus, carYear, carInsuranceDate, carCheckDate, carPrice, carHeader, carHeaderPhone)
        result = carInfoDal.insert(carInfo)
        if result > 0:
            result1 = carStockInfoDal.carAmountAddOne(carType)
            if result1 > 0:
                return f"添加成功 <a href='/carInfoList/{carType}'>刷新</a>"
            else:
                return f"未知错误 <a href='/carInfoList/{carType}'>刷新</a>"
        elif result == -1:
            return "车牌号已存在，请检查重试！ <a href='/addCarInfo'>刷新</a>"
        elif result == -2:
            return "输入内容过长，请检查重试！ <a href='/addCarInfo'>刷新</a>"
        else:
            return f"添加失败 <a href='/carInfoList/{carType}'>刷新</a>"
    except ValueError:
        return "输入不能为空！  <a href='/addCarInfo'>刷新</a>"
    





## 工作人员信息
# 工作人员信息列表
@app.route('/workerList')
def workerList():
    result = workerDal.queryAll()
    return render_template('workerList.html', info=result)

# 工作人员信息修改
@app.route('/updateWorkerInfo/<workerNumber>')
def updateWorkerInfo(workerNumber):
    result = workerDal.queryByWorkerName(workerNumber)
    if result is None:
        return "工作人员信息不存在，请检查重试！ <a href='/carStockList'>返回首页</a>"
    else:
        result1 = workerTypeDal.queryAll()
        return render_template('updateWorkerInfo.html', info=result, info1=result1)

# 工作人员信息修改提交
@app.route('/updateWorkerInfoSubmit', methods=['POST'])
def updateWorkerInfoSubmit():
    workerName = request.form.get('workerName')
    workerAge = request.form.get('workerAge')
    if int(workerAge) < 18 or int(workerAge) >= 100:
        return f"年龄输入有误，请检查重试！ <a href='/updateWorkerInfo/{workerName}'>刷新</a>"
    workerType = request.form.get('workerType')
    workerDriver = request.form.get('workerDriver')
    workerDriverYear = request.form.get('workerDriverYear')
    if int(workerAge) - int(workerDriverYear) < 18 or int(workerDriverYear) <= 0:
        return f"驾龄输入有误，请检查重试！ <a href='/updateWorkerInfo/{workerName}'>刷新</a>"
    workerPhone = request.form.get('workerPhone')
    if int(workerPhone) <= 0:
        return f"联系方式有误，请检查重试！ <a href='/updateWorkerInfo/{workerName}'>刷新</a>"
    elif len(workerPhone) != 11:
        return f"联系方式有误，请检查重试！ <a href='/updateWorkerInfo/{workerName}'>刷新</a>"
    worker = Worker(workerName, workerAge, workerType, workerDriver, workerDriverYear, workerPhone)
    result = workerDal.updateByWorkerName(worker)
    if result > 0:
        return f"修改成功 <a href='/workerList'>刷新</a>"
    elif result == 0:
        return f"数据未更改 <a href='/workerList'>刷新</a>"
    elif result == -2:
        return f"输入内容过长，请检查重试！ <a href='/updateWorkerInfo/{workerName}'>刷新</a>"

# 工作人员信息删除
@app.route('/deleteWorkerInfo/<workerName>')
def deleteWorkerInfo(workerName):
    flag = 'deleteWorkerInfo'
    result = workerDal.queryByWorkerName(workerName)
    if result is None:
        return f"抱歉，删除失败，工作人员不存在！ <a href='/workerList'>返回人员页面</a>"
    else:
        return render_template('/deleteConfirm.html', delInfo=workerName, flag=flag)
    
# 工作人员信息添加
@app.route('/addWorkerInfo')
def addWorkerInfo():
    result = workerTypeDal.queryAll()
    return render_template('addWorkerInfo.html', info=result)

# 工作人员信息添加提交
@app.route('/addWorkerInfoSubmit', methods=['POST'])
def addWorkerInfoSubmit():
    try:
        workerName = request.form.get('workerName')
        workerAge = request.form.get('workerAge')
        if int(workerAge) < 18 or int(workerAge) >= 100:
            return "年龄输入有误，请检查重试！ <a href='/addWorkerInfo'>刷新</a>"
        workerType = request.form.get('workerType')
        workerDriver = request.form.get('workerDriver')
        workerDriverYear = request.form.get('workerDriverYear')
        if int(workerAge) - int(workerDriverYear) < 18 or int(workerDriverYear) <= 0:
            return "驾龄输入有误，请检查重试！ <a href='/addWorkerInfo'>刷新</a>"
        workerPhone = request.form.get('workerPhone')
        if int(workerPhone) <= 0:
            return "联系方式有误，请检查重试！ <a href='/addWorkerInfo'>刷新</a>"
        elif len(workerPhone) != 11:
            return "联系方式有误，请检查重试！ <a href='/addWorkerInfo'>刷新</a>"
        worker = Worker(workerName, workerAge, workerType, workerDriver, workerDriverYear, workerPhone)
        result = workerDal.insert(worker)
        if result > 0:
            return "添加成功 <a href='/workerList'>刷新</a>"
        # elif result == -1:
        #     return "员工姓名已存在，请检查重试！ <a href='/addWorkerInfo'>刷新</a>"
        elif result == -2:
            return "输入内容过长，请检查重试！ <a href='/addWorkerInfo'>刷新</a>"
        else:
            return "添加失败 <a href='/workerList'>刷新</a>"
    except ValueError:
        return "输入不能为空！ <a href='/addWorkerInfo'>刷新</a>"
    
    





## 车辆使用信息
# 车辆使用信息列表
@app.route('/carUseList')
def carUseList():
    result = carUseInfoDal.queryAll()
    return render_template('carUseList.html', info=result)

# 车辆使用信息修改
@app.route('/updateCarUseList/<carUseId>')
def updateCarUseInfo(carUseId):
    result = carUseInfoDal.queryByCarUseId(carUseId)
    if result is None:
        return "车辆调用记录不存在，请检查重试！ <a href='/carStockList'>返回首页</a>"
    else:
        return render_template('updateCarUseInfo.html', info=result)

# 车辆使用信息修改提交
@app.route('/updateCarUseInfoSubmit', methods=['POST'])
def updateCarUseInfoSubmit():
    carUseId = request.form.get('carUseId')
    carNumber = request.form.get('carNumber')
    if len(carNumber) < 7 or len(carNumber) > 8:
        return f"车牌号只有7位和8位（电车）！ <a href='/updateCarUseList/{carUseId}'>刷新</a>"
    useMotive = request.form.get('useMotive')
    useDate = request.form.get('useDate')
    useTime = request.form.get('useTime')
    if int(useTime) <= 0:
        return f"使用时长必须大于0！ <a href='/updateCarUseList/{carUseId}'>刷新</a>"
    workerName = request.form.get('workerName')
    workerPhone = request.form.get('workerPhone')
    if int(workerPhone) <= 0:
        return f"使用人员联系方式有误，请检查重试！ <a href='/updateCarUseList/{carUseId}'>刷新</a>"
    elif len(workerPhone) != 11:
        return f"使用人员联系方式有误，请检查重试！ <a href='/updateCarUseList/{carUseId}'>刷新</a>"
    carHeader = request.form.get('carHeader')
    carHeaderPhone = request.form.get('carHeaderPhone')
    if int(carHeaderPhone) <= 0:
        return f"负责人员联系方式有误，请检查重试！ <a href='/updateCarUseList/{carUseId}'>刷新</a>"
    elif len(carHeaderPhone) != 11:
        return f"负责人员联系方式有误，请检查重试！ <a href='/updateCarUseList/{carUseId}'>刷新</a>"
    carTypeHeader = request.form.get('carTypeHeader')
    carTypeHeaderPhone = request.form.get('carTypeHeaderPhone')
    if int(carTypeHeaderPhone) <= 0:
        return f"批准人员联系方式有误，请检查重试！ <a href='/updateCarUseList/{carUseId}'>刷新</a>"
    elif len(carTypeHeaderPhone) != 11:
        return f"批准人员联系方式有误，请检查重试！ <a href='/updateCarUseList/{carUseId}'>刷新</a>"
    carUseInfo = CarUseInfo(carUseId, carNumber, useMotive, useDate, useTime, workerName, workerPhone, carHeader, carHeaderPhone, carTypeHeader, carTypeHeaderPhone)
    result = carUseInfoDal.updateByCarUseId(carUseInfo)
    if result > 0:
        return f"修改成功 <a href='/carUseList'>刷新</a>"
    elif result == 0:
        return f"数据未更改 <a href='/carUseList'>刷新</a>"
    elif result == -2:
        return f"输入内容过长，请检查重试！ <a href='/updateCarUseList/{carUseId}'>刷新</a>"

# 车辆使用信息删除
@app.route('/deleteCarUseList/<carUseId>')
def deleteCarUseInfo(carUseId):
    flag = 'deleteCarUseInfo'
    result = carUseInfoDal.queryByCarUseId(carUseId)
    print(result)
    if result is None:
        return f"抱歉，删除失败，记录编号不存在！ <a href='/carStockList'>返回首页</a> 或者 <a href='/carUseList'>返回车辆调用记录页面</a>"
    else:
        return render_template('/deleteConfirm.html', delInfo=carUseId, flag=flag)
     
# 车辆使用信息添加
@app.route('/addCarUseInfo')
def addCarUseInfo():
    return render_template('addCarUseInfo.html')

# 车辆使用信息添加提交
@app.route('/addCarUseInfoSubmit', methods=['POST'])
def addCarUseInfoSubmit():
    try:
        carUseId = request.form.get('carUseId')
        if int(carUseId) <= 0:
            return "记录编号必须大于0！ <a href='/addCarUseInfo'>刷新</a>"
        carNumber = request.form.get('carNumber')
        if len(carNumber) < 7 or len(carNumber) > 8:
            return f"车牌号只有7位和8位（电车）！ <a href='/addCarUseInfo'>刷新</a>"
        useMotive = request.form.get('useMotive')
        useDate = request.form.get('useDate')
        useTime = request.form.get('useTime')
        if int(useTime) <= 0:
            return f"使用时长必须大于0！ <a href='/addCarUseInfo'>刷新</a>"
        workerName = request.form.get('workerName')
        workerPhone = request.form.get('workerPhone')
        if int(workerPhone) <= 0:
            return f"使用人员联系方式有误，请检查重试！ <a href='/addCarUseInfo'>刷新</a>"
        elif len(workerPhone) != 11:
            return f"使用人员联系方式有误，请检查重试！ <a href='/addCarUseInfo'>刷新</a>"
        carHeader = request.form.get('carHeader')
        carHeaderPhone = request.form.get('carHeaderPhone')
        if int(carHeaderPhone) <= 0:
            return f"负责人员联系方式有误，请检查重试！ <a href='/addCarUseInfo'>刷新</a>"
        elif len(carHeaderPhone) != 11:
            return f"负责人员联系方式有误，请检查重试！ <a href='/addCarUseInfo'>刷新</a>"
        carTypeHeader = request.form.get('carTypeHeader')
        carTypeHeaderPhone = request.form.get('carTypeHeaderPhone')
        if int(carTypeHeaderPhone) <= 0:
            return f"批准人员联系方式有误，请检查重试！ <a href='/addCarUseInfo'>刷新</a>"
        elif len(carTypeHeaderPhone) != 11:
            return f"批准人员联系方式有误，请检查重试！ <a href='/addCarUseInfo'>刷新</a>"
        carUserInfo = CarUseInfo(carUseId, carNumber, useMotive, useDate, useTime, workerName, workerPhone, carHeader, carHeaderPhone, carTypeHeader, carTypeHeaderPhone)
        result = carUseInfoDal.insert(carUserInfo)
        if result > 0:
            return f"添加成功 <a href='/carUseList'>刷新</a>"
        elif result == -1:
            return "记录编号已存在，请检查重试！ <a href='/addCarUseInfo'>刷新</a>"
        elif result == -2:
            return "输入内容过长，请检查重试！ <a href='/addCarUseInfo'>刷新</a>"
        else:
            return f"添加失败 <a href='/carUseList'>刷新</a>"
    except ValueError:
        return "输入不能为空！ <a href='/addCarUseInfo'>刷新</a>"




#######################################################
# 删除确认身份
@app.route('/deleteConfirmSubmit/<flag>',methods=['POST'])
def deleteConfirmSubmit(flag):
    delInfo = request.form.get('delInfo')
    passwd = request.form.get('passwd')
    passWord = adminPassWordDal.queryPassWord()
    if passwd == passWord[0]:
        if flag == 'deleteCarStockInfo':
            result = carStockInfoDal.deleteByCarType(delInfo)
            if result > 0:
                return f"删除成功 <a href='/carStockList'>刷新</a>"
            else:
                return f"删除失败，类型中还有数据！ <a href='/carStockList'>刷新</a>"
        elif flag == 'deleteWorkerInfo':
            result = workerDal.deleteByWorkerName(delInfo)
            if result > 0:
                return f"删除成功 <a href='/workerList'>刷新</a>"
            else:
                return f"删除失败 <a href='/workerList'>刷新</a>"
        elif flag == 'deleteCarUseInfo':
            result = carUseInfoDal.deleteByCarUseId(delInfo)
            if result > 0:
                return f"删除成功 <a href='/carUseList'>刷新</a>"
            else:
                return f"删除失败 <a href='/carUseList'>刷新</a>"
    else:
        if flag == 'deleteCarStockInfo':
            return f"抱歉，密码错误，无法确认您的身份！ <a href='/carStockList'>重新操作</a>"
        elif flag == 'deleteWorkerInfo':
            return f"抱歉，密码错误，无法确认您的身份！ <a href='/workerList'>重新操作</a>"
        elif flag == 'deleteCarUseInfo':
            return f"抱歉，密码错误，无法确认您的身份！ <a href='/carUseList'>重新操作</a>"
#######################################################



#######################################################
# 管理员密码设置
@app.route('/updateAdminPassWord')
def updateAdminPassWord():
    return render_template('/updateAdminPassWord.html')

# 修改管理员密码提交
@app.route('/updateAdminPassWordSubmit', methods=['POST'])
def updateAdminPassWordSubmit():
    oldPassWord = request.form.get('oldPassWord')
    newPassWord = request.form.get('newPassWord')
    newPassWordConfirm = request.form.get('newPassWordConfirm')
    oldPassWordConfirm = adminPassWordDal.queryPassWord()
    if oldPassWord == oldPassWordConfirm[0]:
        if newPassWord == newPassWordConfirm:
            result = adminPassWordDal.updatePassWord(oldPassWord, newPassWord)
            if result > 0:
                return "修改密码成功，请牢记密码！ <a href='/carStockList'>返回首页</a>"
            elif result == 0:
                return "密码未修改！ <a href='/carStockList'>返回首页</a>"
            elif result == -2:
                return "密码最长10位，请检查重试！ <a href='/updateAdminPassWord'>刷新</a>"
        else:
            return "两次输入新密码不一样，请重试！ <a href='/updateAdminPassWord'>刷新</a>"
    else:
        return "抱歉，旧密码不正确，请重试！ <a href='/updateAdminPassWord'>刷新</a>"

#######################################################



## 查看车辆存储图表
@app.route('/barChart')
def barChart():
    return render_template('/barChart.html')

@app.route('/barChartData')
## 车辆存储图表数据
def barChartData():
    # 车辆总数量
    carAmount = carInfoDal.queryCarAmount()
    # 车辆未使用数量
    carNotUseAmount = carInfoDal.queryCarStatusIsNotUseAmount()
    # 车辆已使用数量
    carUseAmount = int(carAmount) - int(carNotUseAmount[0])
    # 车辆类型和库存信息
    carTypeAndAmount = carStockInfoDal.queryCarTypeAndCarAmount()
    # 工作人员类型和数量信息
    workerTypeCount = workerDal.queryWorkerTypeCount()
    dict1 = {}
    dict1["data1"] = [{'name':'在使用', 'value':carUseAmount}, {'name':'未使用', 'value':carNotUseAmount}]
    dict1["data2"] = [{'name':i[0], 'value':i[1]} for i in carTypeAndAmount]
    dict1["data3"] = [{'name':i[0], 'value':i[1]} for i in workerTypeCount]
    return jsonify(dict1)



if __name__ == '__main__':
    app.run(host='127.0.0.1', port=5000, debug=True)
